/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2025-04-07
 * Time: 13:21
 */
public class Demo13 {
    //D:\Java\bin-->jconsole.exe
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            while(!Thread.currentThread().isInterrupted()) {// !(false->true->false)
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);//sleep被唤醒后会把isInterrupted标志位设为false
                } catch (InterruptedException e) {
                    //1.线程立即终止
                    //break;

                    //2.线程稍后再终止
                    //....do something

                    //3.线程不终止
                    //如果什么也不做，那么就会一直循环打印hello thread 是因为sleep的原因
                }
            }
        });
        t.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main线程结束");
        t.interrupt();//将isInterrupted方法内部的标志位设为true
    }
}
